<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Java笔记 | lilei</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/images/icons/logo.png">
    <link rel="apple-touch-icon" href="/images/icons/logo.png">
    <link rel="manifest" href="/manifest.json">
    <script type="text/javascript" src="/assets/js/load.js"></script>
    <meta name="description" content="个人网站">
    <meta name="image" content="http://www.lileiblog.xyz/images/Java内置异常.png">
    <meta name="twitter:title" content="Java笔记">
    <meta name="twitter:description" content="">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:image" content="http://www.lileiblog.xyz/images/Java内置异常.png">
    <meta name="twitter:url" content="http://www.lileiblog.xyz/Java/Java%E7%AC%94%E8%AE%B0.html">
    <meta property="og:type" content="article">
    <meta property="og:title" content="Java笔记">
    <meta property="og:description" content="">
    <meta property="og:image" content="http://www.lileiblog.xyz/images/Java内置异常.png">
    <meta property="og:url" content="http://www.lileiblog.xyz/Java/Java%E7%AC%94%E8%AE%B0.html">
    <meta property="og:site_name" content="lilei">
    <meta itemprop="name" content="Java笔记">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="http://www.lileiblog.xyz/images/Java内置异常.png">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/logo.png">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="keywords" content="lilei,vue,vuepress,vuepress-theme,theme,主题,vuepress主题,blog
        ,vuepress-blog,java,python,shell,sql,golang,script,shell script,nginx,windows,去广告,androd,google drive
        ,one drive,idea,eclipse,git,小程序">
    <meta name="referrer" content="never">
    
    <link rel="preload" href="/assets/css/0.styles.8932179b.css" as="style"><link rel="preload" href="/assets/js/app.269009d6.js" as="script"><link rel="preload" href="/assets/js/3.974b9720.js" as="script"><link rel="preload" href="/assets/js/28.c124245a.js" as="script"><link rel="prefetch" href="/assets/js/10.5915e99b.js"><link rel="prefetch" href="/assets/js/11.ff732762.js"><link rel="prefetch" href="/assets/js/12.8bb86d91.js"><link rel="prefetch" href="/assets/js/13.18bde5b0.js"><link rel="prefetch" href="/assets/js/14.314fae34.js"><link rel="prefetch" href="/assets/js/15.0a4ff48f.js"><link rel="prefetch" href="/assets/js/16.ffaf1503.js"><link rel="prefetch" href="/assets/js/17.49a31a6e.js"><link rel="prefetch" href="/assets/js/18.7e6443bf.js"><link rel="prefetch" href="/assets/js/19.6880cc9a.js"><link rel="prefetch" href="/assets/js/20.1fb3f255.js"><link rel="prefetch" href="/assets/js/21.0cd39eea.js"><link rel="prefetch" href="/assets/js/22.392d85cb.js"><link rel="prefetch" href="/assets/js/23.f50adb15.js"><link rel="prefetch" href="/assets/js/24.43e324e1.js"><link rel="prefetch" href="/assets/js/25.e3663205.js"><link rel="prefetch" href="/assets/js/26.da141fb8.js"><link rel="prefetch" href="/assets/js/27.6c05235a.js"><link rel="prefetch" href="/assets/js/29.d185870d.js"><link rel="prefetch" href="/assets/js/30.8587d422.js"><link rel="prefetch" href="/assets/js/31.dc382b56.js"><link rel="prefetch" href="/assets/js/32.20ba32e9.js"><link rel="prefetch" href="/assets/js/33.6ecd7de9.js"><link rel="prefetch" href="/assets/js/34.2b91c13a.js"><link rel="prefetch" href="/assets/js/35.66ed0733.js"><link rel="prefetch" href="/assets/js/36.ce7bca84.js"><link rel="prefetch" href="/assets/js/37.d00bb5ac.js"><link rel="prefetch" href="/assets/js/38.c3ecbb6f.js"><link rel="prefetch" href="/assets/js/39.308f4175.js"><link rel="prefetch" href="/assets/js/4.520f6ecc.js"><link rel="prefetch" href="/assets/js/40.f4b98bc2.js"><link rel="prefetch" href="/assets/js/41.95fae64f.js"><link rel="prefetch" href="/assets/js/42.fe4f877b.js"><link rel="prefetch" href="/assets/js/43.ca8f222e.js"><link rel="prefetch" href="/assets/js/44.4d4ee79e.js"><link rel="prefetch" href="/assets/js/45.79178b33.js"><link rel="prefetch" href="/assets/js/46.c3817d0b.js"><link rel="prefetch" href="/assets/js/47.b8252443.js"><link rel="prefetch" href="/assets/js/48.df9d5d3b.js"><link rel="prefetch" href="/assets/js/49.d812fdb2.js"><link rel="prefetch" href="/assets/js/5.f1a24a16.js"><link rel="prefetch" href="/assets/js/50.55cfcaa8.js"><link rel="prefetch" href="/assets/js/51.b8608b02.js"><link rel="prefetch" href="/assets/js/52.52c5e00d.js"><link rel="prefetch" href="/assets/js/53.3a9bd5fb.js"><link rel="prefetch" href="/assets/js/54.a4240c13.js"><link rel="prefetch" href="/assets/js/55.01c4b876.js"><link rel="prefetch" href="/assets/js/56.f29549a3.js"><link rel="prefetch" href="/assets/js/57.01438a04.js"><link rel="prefetch" href="/assets/js/58.29bb4626.js"><link rel="prefetch" href="/assets/js/59.e8b89408.js"><link rel="prefetch" href="/assets/js/6.8c478b39.js"><link rel="prefetch" href="/assets/js/60.bedb5381.js"><link rel="prefetch" href="/assets/js/61.bdfbe584.js"><link rel="prefetch" href="/assets/js/62.cb825d1a.js"><link rel="prefetch" href="/assets/js/63.a9516572.js"><link rel="prefetch" href="/assets/js/64.aa854ed7.js"><link rel="prefetch" href="/assets/js/65.285f883d.js"><link rel="prefetch" href="/assets/js/66.12849f37.js"><link rel="prefetch" href="/assets/js/67.c18b00e4.js"><link rel="prefetch" href="/assets/js/68.fa59daa9.js"><link rel="prefetch" href="/assets/js/69.e9d5dda4.js"><link rel="prefetch" href="/assets/js/7.cfb0d0ea.js"><link rel="prefetch" href="/assets/js/70.db126cce.js"><link rel="prefetch" href="/assets/js/71.6acb04cd.js"><link rel="prefetch" href="/assets/js/72.7ff0ab11.js"><link rel="prefetch" href="/assets/js/73.9a66da79.js"><link rel="prefetch" href="/assets/js/74.0a38a030.js"><link rel="prefetch" href="/assets/js/75.7b32dbb3.js"><link rel="prefetch" href="/assets/js/8.cb9c08e5.js"><link rel="prefetch" href="/assets/js/9.ad652cfe.js"><link rel="prefetch" href="/assets/js/vendors~flowchart.110a1065.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8932179b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/icons/logo.png" alt="lilei" class="logo"> <span class="site-name can-hide">lilei</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link router-link-active">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link router-link-active">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Java</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/Java/" aria-current="page" class="sidebar-link">Java</a></li><li><a href="/Java/Annotation.html" class="sidebar-link">Annotation</a></li><li><a href="/Java/JDK安装配置.html" class="sidebar-link">JDK安装配置</a></li><li><a href="/Java/JDK工具.html" class="sidebar-link">JDK工具</a></li><li><a href="/Java/Java构建管理.html" class="sidebar-link">Java构建管理</a></li><li><a href="/Java/Java笔记.html" class="active sidebar-link">Java笔记</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#flag" class="sidebar-link">Flag</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#多行字符串" class="sidebar-link">多行字符串</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#函数重载" class="sidebar-link">函数重载</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#访问控制修饰符" class="sidebar-link">访问控制修饰符</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#classpath意义" class="sidebar-link">classpath意义</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#日期时间" class="sidebar-link">日期时间</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#roundingmode" class="sidebar-link">RoundingMode</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#java锁" class="sidebar-link">Java锁</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#java异常" class="sidebar-link">Java异常</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#协程" class="sidebar-link">协程</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#http" class="sidebar-link">HTTP</a></li><li class="sidebar-sub-header"><a href="/Java/Java笔记.html#泛型generics" class="sidebar-link">泛型generics</a></li></ul></li><li><a href="/Java/ORM.html" class="sidebar-link">ORM</a></li><li><a href="/Java/SPI.html" class="sidebar-link">SPI</a></li><li><a href="/Java/Spring.html" class="sidebar-link">Spring</a></li><li><a href="/Java/Tomcat.html" class="sidebar-link">Tomcat</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="java笔记"><a href="#java笔记" class="header-anchor">#</a> Java笔记</h1> <p></p><div class="table-of-contents"><ul><li><a href="#flag">Flag</a></li><li><a href="#多行字符串">多行字符串</a></li><li><a href="#函数重载">函数重载</a></li><li><a href="#访问控制修饰符">访问控制修饰符</a></li><li><a href="#classpath意义">classpath意义</a></li><li><a href="#日期时间">日期时间</a></li><li><a href="#roundingmode">RoundingMode</a><ul><li><a href="#几个参数详解">几个参数详解</a></li></ul></li><li><a href="#java锁">Java锁</a><ul><li><a href="#synchronized">synchronized</a></li></ul></li><li><a href="#java异常">Java异常</a></li><li><a href="#协程">协程</a></li><li><a href="#http">HTTP</a></li><li><a href="#泛型generics">泛型generics</a></li></ul></div><p></p> <h2 id="flag"><a href="#flag" class="header-anchor">#</a> Flag</h2> <ul><li><a href="https://www.yiibai.com/html/java" target="_blank" rel="noopener noreferrer">https://www.yiibai.com/html/java/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://www.zhihu.com/question/26762707/answer/890181997" target="_blank" rel="noopener noreferrer">什么是 hash<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.jianshu.com/p/101c263cd93e" target="_blank" rel="noopener noreferrer">什么是散列表(Hash Table)<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://yuanrengu.com/2020/ba184259.html" target="_blank" rel="noopener noreferrer">HashMap在Jdk1.7和1.8中的实现<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/chengxiao/p/6059914.html" target="_blank" rel="noopener noreferrer">HashMap的底层结构和实现原理<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/chengxiao/p/6842045.html" target="_blank" rel="noopener noreferrer">ConcurrentHashMap实现原理及源码分析<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.zcfy.cc/article/data-structures-for-beginners-arrays-hashmaps-and-lists" target="_blank" rel="noopener noreferrer">初学者应该了解的数据结构：Array、HashMap 与 List<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://zhuanlan.zhihu.com/p/67949045" target="_blank" rel="noopener noreferrer">强一致性、弱一致性、最终一致性、读写一致性、单调读、因果一致性 的区别与联系<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="http://www.ruanyifeng.com/blog/2018/07/cap.html" target="_blank" rel="noopener noreferrer">CAP 定理的含义<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/c-x-a/p/9478643.html" target="_blank" rel="noopener noreferrer">二进制运算<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.jianshu.com/p/d75b0a461380" target="_blank" rel="noopener noreferrer">什么是位运算<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/shuaigexiaobo/article/details/88535745" target="_blank" rel="noopener noreferrer">java运算符<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/itfly8/p/6062757.html" target="_blank" rel="noopener noreferrer">数据库扩展性设计：使用二进制解决一条记录关联多个状态的问题<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="多行字符串"><a href="#多行字符串" class="header-anchor">#</a> 多行字符串</h2> <ul><li>Multiline String 多行字符串</li> <li>Template String 模板字符串</li> <li>Text Blocks 文本块</li></ul> <blockquote><p>Java 13 Text Blocks 第一次预览版，Java 14 Text Blocks 第二次预览版，Java 15 Text Blocks 正式版</p></blockquote> <h2 id="函数重载"><a href="#函数重载" class="header-anchor">#</a> 函数重载</h2> <ul><li>方法名相同,方法参数的个数和类型不同,通过个数和类型的不同来区分不同的函数;</li> <li>方法的重载跟返回值类型和修饰符无关,Java的重载是发生在本类中的,重载的条件是在本类中有多个方法名相同;</li> <li>参数列表不同(参数个数不同、参数类型不同)跟返回值无关;</li></ul> <h2 id="访问控制修饰符"><a href="#访问控制修饰符" class="header-anchor">#</a> 访问控制修饰符</h2> <table><thead><tr><th>修饰符</th> <th>当前类</th> <th>同一包内</th> <th>子孙类(同一包)</th> <th>子孙类(不同包)</th> <th>其他包</th></tr></thead> <tbody><tr><td>public(interface default)</td> <td>Y</td> <td>Y</td> <td>Y</td> <td>Y</td> <td>Y</td></tr> <tr><td>protected</td> <td>Y</td> <td>Y</td> <td>Y</td> <td>Y/N</td> <td>N</td></tr> <tr><td>default</td> <td>Y</td> <td>Y</td> <td>Y</td> <td>N</td> <td>N</td></tr> <tr><td>private</td> <td>Y</td> <td>N</td> <td>N</td> <td>N</td> <td>N</td></tr></tbody></table> <p><strong><code>protected</code>需要从以下两个点来分析说明</strong></p> <blockquote><p>子类与基类在同一包中：被声明为<code>protected</code>的变量、方法和构造器能被同一个包中的任何其他类访问；</p></blockquote> <blockquote><p>子类与基类不在同一包中：那么在子类中，子类实例可以访问其从基类继承而来的<code>protected</code>方法，而不能访问基类实例的<code>protected</code>方法。</p></blockquote> <h2 id="classpath意义"><a href="#classpath意义" class="header-anchor">#</a> classpath意义</h2> <ul><li><a href="https://segmentfault.com/a/1190000015802324" target="_blank" rel="noopener noreferrer">java项目中的classpath到底是什么<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/qq_30038111/article/details/82116559" target="_blank" rel="noopener noreferrer">spring classpath:和classpath*:区别和实际应用<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/qq_33393542/article/details/80322141" target="_blank" rel="noopener noreferrer">java项目中的classpath到底指向的哪里<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/pengmm1990/article/details/68951389" target="_blank" rel="noopener noreferrer">eclipse项目中.classpath文件详解<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><code>classpath</code>：只会到你的<code>class</code>路径中查找文件，和<code>classpath:/</code>是等价的，都是相对于类的根路径
<ul><li><code>src</code>不是<code>classpath</code>，<code>WEB-INF/classes</code>和<code>lib</code>才是<code>classpath</code>，<code>WEB-INF/</code>是资源目录, 客户端不能直接访问</li> <li><code>WEB-INF/classes</code>目录存放<code>src</code>目录<code>java</code>文件编译之后的<code>class</code>文件、<code>xml</code>、<code>properties</code>等资源配置文件</li> <li><code>lib</code>和<code>classes</code>同属<code>classpath</code>，两者的访问优先级为: <code>lib</code> &gt; <code>classes</code></li></ul></li> <li><code>classpath*</code>：不仅包含<code>class</code>路径，还包括<code>jar</code>文件中（<code>class</code>路径）进行查找</li></ul> <blockquote><p>注意：用<code>classpath*</code>需要遍历所有的<code>classpath</code>，所以加载速度是很慢，尽量避免使用。
<code>**</code>表示在任意目录下，也就是说在<code>WEB-INF/classes/</code>下任意层的目录</p></blockquote> <table><thead><tr><th>前缀</th> <th>例子</th> <th>说明</th></tr></thead> <tbody><tr><td>classpath:</td> <td>classpath:com/myapp/config.xml</td> <td>从classpath中加载。</td></tr> <tr><td>file:</td> <td>file:/data/config.xml</td> <td>作为 URL 从文件系统中加载。</td></tr> <tr><td>http:</td> <td>http://myserver/logo.png</td> <td>作为 URL 加载。</td></tr> <tr><td>(none)</td> <td>/data/config.xml</td> <td>根据 ApplicationContext 进行判断。</td></tr></tbody></table> <h2 id="日期时间"><a href="#日期时间" class="header-anchor">#</a> 日期时间</h2> <ul><li><a href="https://codertang.com/2018/12/24/jdk8-datetime" target="_blank" rel="noopener noreferrer">jdk8时间日期<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li>可变性 : 像日期和时间这样的类应该是不可变的,返回一个值,原来的对象不变</li> <li>偏移性 : Date中的年份是从1900开始的,而月份是从0开始的</li> <li>日期表示需要减<code>new Date(2020-1900,9-1,8)</code> 这样才可以表示2020年9月8日</li> <li>格式化: 格式化日期只对Date有用,Calendar则不行</li> <li>线程不安全的,不能处理闰秒等</li> <li>Java8吸收了<code>Joda-Time</code>（该项目作者参与了Java8的time包开发）精华，开启了新的API</li></ul> <p><strong>java.lang.System类</strong></p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token comment">// 用于返回当前时间与1970年1月1日0:0:0之间以毫秒为单位的时间戳</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">native</span> <span class="token keyword">long</span> <span class="token function">currentTimeMillis</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 返回正在运行的Java虚拟机的当前值,高分辨率时间源，以纳秒为单位</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">native</span> <span class="token keyword">long</span> <span class="token function">nanoTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p><strong>java.util.Date类</strong></p> <ul><li>两个构造器
<ul><li><code>new Date();</code> 当前时间</li> <li><code>new Date(Long 毫秒数)</code> 根据毫秒数创建指定日期</li></ul></li> <li>两个方法的使用
<ul><li><code>toString(</code>)` 显示当前的年,月,日,时,分,秒</li> <li><code>getTime()</code> 获取当前date对象的对应的毫秒数(时间戳)</li></ul></li></ul> <ul><li><code>java.util.Date</code>和<code>java.sql.Date</code>互相转换</li></ul> <div class="language-java extra-class"><pre class="language-java"><code><span class="token class-name">Date</span> date <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>sql<span class="token punctuation">.</span></span>Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>sql<span class="token punctuation">.</span></span>Date</span> date2 <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>sql<span class="token punctuation">.</span></span>Date</span><span class="token punctuation">)</span> date<span class="token punctuation">;</span>
<span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>sql<span class="token punctuation">.</span></span>Date</span> date3 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name"><span class="token namespace">java<span class="token punctuation">.</span>sql<span class="token punctuation">.</span></span>Date</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getTime</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p><strong>java.text.SimpleDateFormat类</strong></p> <blockquote><p>Date类的API不易于国际化，大部分被废弃，并且不是线程安全的</p></blockquote> <ul><li><code>format()</code> 方法 按照具体的格式格式化时间</li> <li><code>parse()</code> 方法 将字符串解析成时间</li></ul> <p><strong><code>java.time</code>的基础包</strong></p> <table><thead><tr><th>java.time</th> <th>包含值对象的基础包</th></tr></thead> <tbody><tr><td>java.time.chrono</td> <td>提供不同日历系统的访问</td></tr> <tr><td>java.time.format</td> <td>格式化和解析时间和日期</td></tr> <tr><td>java.time.temporal</td> <td>包含底层框架和扩展特性</td></tr> <tr><td>java.time.zone</td> <td>包含时区支持的类</td></tr></tbody></table> <p><strong>新的<code>java.time</code>包含了如下子类</strong></p> <table><thead><tr><th>类</th> <th>作用</th> <th>说明</th></tr></thead> <tbody><tr><td>Instant</td> <td>表示时刻</td> <td>对应jdk7之前的Date</td></tr> <tr><td>LocalDateTime</td> <td>获取当前系统的日期时间(内部不记录时区)</td> <td>可以认为由LocalDate和LocalTime组成</td></tr> <tr><td>LocalDate</td> <td>获取当前系统的日期</td> <td></td></tr> <tr><td>LocalTime</td> <td>获取当前系统的时间</td> <td></td></tr> <tr><td>ZoneId</td> <td>时区，&quot;5:00&quot;和&quot;Europe/Paris&quot;、&quot;Asia/Shanghai&quot;</td> <td>除了处理与标准时间的时间差还处理地区时（夏令时，冬令时等）</td></tr> <tr><td>ZoneOffset</td> <td>时区，只处理 &quot;6:00&quot;</td> <td>ZoneOffset是ZoneId的子类</td></tr> <tr><td>ZoneDateTime</td> <td>一个在ISO-8601日历系统特定时区的日期和时间</td> <td>其中每个时区都有对应的Id,每个地区Id都有&quot;{区域}/{城市}&quot; 例如 Asia/Shanghai等</td></tr> <tr><td>ZonedDateTime</td> <td>处理日期和时间与相应的时区</td> <td></td></tr> <tr><td>Duration</td> <td>持续时间,用于计算两个&quot;时间&quot;的间隔</td> <td></td></tr> <tr><td>Period</td> <td>日期间隔,用于计算两个&quot;日期&quot;的间隔</td> <td></td></tr> <tr><td>Clock</td> <td>使用时区提供对当前即时，日期和时间的访问</td> <td></td></tr></tbody></table> <p><strong>方法前缀</strong></p> <table><thead><tr><th>前缀</th> <th>含义</th> <th>示例</th></tr></thead> <tbody><tr><td>now</td> <td>静态工厂方法, 用当前时间创建实例</td> <td>LocalDate.now();</td></tr> <tr><td>of</td> <td>静态工厂方法</td> <td>LocalDate.of(2018, 12, 20);</td></tr> <tr><td>parse</td> <td>静态工厂方法, 关注于解析</td> <td>LocalDate.parse(&quot;2018-12-20&quot;);</td></tr> <tr><td>get</td> <td>获取某个字段的值</td> <td>localDate.getYear();</td></tr> <tr><td>is</td> <td>比对判断</td> <td>localDate.isAfter(LocalDate.now());</td></tr> <tr><td>with</td> <td>基于当前实例创建新的实例, 但部分字段被更新</td> <td>localDate.withMonth(3);</td></tr> <tr><td>plus</td> <td>在当前实例基础上增加(值可负), 返回新实例</td> <td>localDate.plusDays(1);</td></tr> <tr><td>minus</td> <td>在当前实例基础上减小(值可负), 返回新实例</td> <td>localDate.minusDays(1);</td></tr> <tr><td>to</td> <td>基于当前实例转换出另一个类型的实例</td> <td>localDateTime.toLocalDate();</td></tr> <tr><td>at</td> <td>把当前对象和另一个对象结合, 生成新的类型的实例</td> <td>localDate.atTime(21, 30, 50)</td></tr> <tr><td>format</td> <td>格式化</td> <td>localDate.format(DateTimeFormatter.ofPattern(&quot;yyyy-MM-dd&quot;));</td></tr></tbody></table> <h2 id="roundingmode"><a href="#roundingmode" class="header-anchor">#</a> RoundingMode</h2> <blockquote><p><code>java.math.RoundingMode</code>是一个舍入枚举类</p></blockquote> <ul><li><a href="https://blog.csdn.net/alanzyy/article/details/8465098" target="_blank" rel="noopener noreferrer">https://blog.csdn.net/alanzyy/article/details/8465098<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://my.oschina.net/sunchp/blog/670909" target="_blank" rel="noopener noreferrer">https://my.oschina.net/sunchp/blog/670909<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/chendaoqiu/article/details/45841283" target="_blank" rel="noopener noreferrer">https://blog.csdn.net/chendaoqiu/article/details/45841283<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h3 id="几个参数详解"><a href="#几个参数详解" class="header-anchor">#</a> 几个参数详解</h3> <ul><li><code>RoundingMode.CEILING</code>(对应<code>BigDecimal.ROUND_CEILING</code>)：取右边最近的整数</li> <li><code>RoundingMode.UP</code>(对应<code>BigDecimal.ROUND_UP</code>)：远离0取整，即负数向左取整，正数向右取整</li> <li><code>RoundingMode.DOWN</code>(对应<code>BigDecimal.ROUND_DOWN</code>)：从不在舍弃(即截断)的小数之前增加数字（其实就是截断的意思）</li> <li><code>RoundingMode.FLOOR</code>(对应<code>BigDecimal.ROUND_FLOOR</code>)：取左边最近的正数</li> <li><code>RoundingMode.HALF_UP</code>(对应<code>BigDecimal.ROUND_HALF_UP</code>)：四舍五入，负数原理同上</li> <li><code>RoundingMode.HALF_DOWN</code>(对应<code>BigDecimal.ROUND_HALF_DOWN</code>)：五舍六入，负数先取绝对值再五舍六入再负数</li> <li><code>RoundingMode.HALF_EVEN</code>(对应<code>BigDecimal.ROUND_HALF_EVEN</code>)：这个比较绕，整数位若是奇数则四舍五入，若是偶数则五舍六入</li> <li><code>RoundingMode.UNNECESSARY</code>(对应<code>BigDecimal.ROUND_UNNECESSARY</code>)：用于断言请求的操作具有精确结果的舍入模式，因此不需要舍入</li></ul> <h2 id="java锁"><a href="#java锁" class="header-anchor">#</a> Java锁</h2> <h3 id="synchronized"><a href="#synchronized" class="header-anchor">#</a> synchronized</h3> <blockquote><p>synchronized(this)以及非static的synchronized方法，只能防止多个线程同时执行同一个对象的同步代码段。</p></blockquote> <blockquote><p>synchronized锁住的是代码还是对象？</p> <blockquote><p>答案是：synchronized锁住的是括号里的对象，而不是代码。对于非static的synchronized方法，锁的就是对象本身也就是this。</p></blockquote></blockquote> <blockquote><p>当synchronized锁住一个对象后，别的线程如果也想拿到这个对象的锁，就必须等待这个线程执行完成释放锁，才能再次给对象加锁，这样才达到线程同步的目的。</p></blockquote> <blockquote><p>即使两个不同的代码段，都要锁同一个对象，那么这两个代码段也不能在多线程环境下同时运行。</p></blockquote> <blockquote><p>所以我们在用synchronized关键字的时候，尽量缩小代码段的范围，尽量不要在整个方法上加同步。这叫减小锁的粒度，使代码更大程度的并发。</p></blockquote> <blockquote><p>static方法可以直接类名加方法名调用，方法中无法使用this，所以它锁的不是this，而是Class，所以static synchronized方法也相当于全局锁，相当于锁住了代码段。</p></blockquote> <h2 id="java异常"><a href="#java异常" class="header-anchor">#</a> Java异常</h2> <ul><li><a href="https://blog.csdn.net/weixin_52566131/article/details/117132098" target="_blank" rel="noopener noreferrer">Java中的异常处理<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><img src="/images/Java%E5%86%85%E7%BD%AE%E5%BC%82%E5%B8%B8.png" alt=""></p> <table><thead><tr><th>未经检查的异常</th> <th>说明</th></tr></thead> <tbody><tr><td>ArithmeticException</td> <td>算术错误，如被0除</td></tr> <tr><td>ArrayIndexOutOfBoundsException</td> <td>数组下标出界</td></tr> <tr><td>ArrayStoreException</td> <td>数组元素赋值类型不兼容</td></tr> <tr><td>ClassCastException</td> <td>非法强制转换类型</td></tr> <tr><td>EnumConstantNotPresentException</td> <td>枚举常量不存在异常。</td></tr> <tr><td>EOFException</td> <td>文件已结束异常</td></tr> <tr><td>Exception</td> <td>根异常。用以描述应用程序希望捕获的情况。</td></tr> <tr><td>FileNotFoundException</td> <td>文件未找到异常</td></tr> <tr><td>IllegalArgumentException</td> <td>调用方法的参数非法</td></tr> <tr><td>IllegalMonitorStateException</td> <td>非法监控操作，如等待一个未锁定线程</td></tr> <tr><td>IllegalStateException</td> <td>环境或应用状态不正确</td></tr> <tr><td>IllegalThreadStateException</td> <td>请求操作与当前线程状态不兼容</td></tr> <tr><td>IndexOutOfBoundsException</td> <td>某些类型索引越界</td></tr> <tr><td>IOException</td> <td>输入输出异常</td></tr> <tr><td>NegativeArrayException</td> <td>数组负下标异常</td></tr> <tr><td>NegativeArraySizeException</td> <td>数组大小为负值异常。当使用负数大小值创建数组时抛出该异常。</td></tr> <tr><td>NullPointerException</td> <td>非法使用空引用</td></tr> <tr><td>NumberFormatException</td> <td>字符串到数字格式非法转换</td></tr> <tr><td>RuntimeException</td> <td>运行时异常。是所有Java虚拟机正常操作期间可以被抛出的异常的父类。</td></tr> <tr><td>SecurityException</td> <td>试图违反安全性</td></tr> <tr><td>SQLException</td> <td>操作数据库异常</td></tr> <tr><td>StringIndexOutOfBoundsException</td> <td>试图在字符串边界之外索引</td></tr> <tr><td>TypeNotPresentException</td> <td>类型不存在异常。</td></tr> <tr><td>UnsupportedOperationException</td> <td>遇到不支持的操作</td></tr></tbody></table> <table><thead><tr><th>检查的异常</th> <th>说明</th></tr></thead> <tbody><tr><td>ClassNotFoundException</td> <td>找不到类</td></tr> <tr><td>CloneNotSupportedException</td> <td>试图克隆一个不能实现Cloneable接口的对象</td></tr> <tr><td>IllegalAccessException</td> <td>对一个类的访问被拒绝</td></tr> <tr><td>InstantiationException</td> <td>试图创建一个抽象类或者抽象接口的对象</td></tr> <tr><td>InterruptedException</td> <td>一个线程被另一个线程中断</td></tr> <tr><td>NoSuchFieldException</td> <td>请求的字段不存在</td></tr> <tr><td>NoSuchMethodException</td> <td>请求的方法不存在</td></tr></tbody></table> <table><thead><tr><th>错误</th> <th>说明</th></tr></thead> <tbody><tr><td>java.lang.AbstractMethodError</td> <td>抽象方法错误</td></tr> <tr><td>java.lang.AssertionError</td> <td>断言错</td></tr> <tr><td>java.lang.ClassCircularityError</td> <td>类循环依赖错误</td></tr> <tr><td>java.lang.ClassFormatError</td> <td>类格式错误</td></tr> <tr><td>java.lang.Error</td> <td>错误</td></tr> <tr><td>java.lang.ExceptionInInitializerError</td> <td>初始化程序错误</td></tr> <tr><td>java.lang.IllegalAccessError</td> <td>违法访问错误</td></tr> <tr><td>java.lang.IncompatibleClassChangeError</td> <td>不兼容的类变化错误</td></tr> <tr><td>java.lang.InstantiationError</td> <td>实例化错误</td></tr> <tr><td>java.lang.InternalError</td> <td>内部错误</td></tr> <tr><td>java.lang.LinkageError</td> <td>链接错误</td></tr> <tr><td>java.lang.NoClassDefFoundError</td> <td>未找到类定义错误</td></tr> <tr><td>java.lang.NoSuchFieldError</td> <td>域不存在错误</td></tr> <tr><td>java.lang.NoSuchMethodError</td> <td>方法不存在错误</td></tr> <tr><td>java.lang.OutOfMemoryError</td> <td>内存不足错误</td></tr> <tr><td>java.lang.StackOverflowError</td> <td>堆栈溢出错误</td></tr> <tr><td>java.lang.UnknownError</td> <td>未知错误</td></tr> <tr><td>java.lang.UnsatisfiedLinkError</td> <td>未满足的链接错误</td></tr> <tr><td>java.lang.UnsupportedClassVersionError</td> <td>不支持的类版本错误</td></tr> <tr><td>java.lang.VerifyError</td> <td>验证错误</td></tr> <tr><td>java.lang.VirtualMachineError</td> <td>虚拟机错误</td></tr> <tr><td>java.lang.ThreadDeath</td> <td>线程结束</td></tr></tbody></table> <h2 id="协程"><a href="#协程" class="header-anchor">#</a> 协程</h2> <blockquote><p>Java语言并没有对协程的原生支持，但是某些开源框架模拟出了协程的功能，<code>Project Loom</code> <code>AJDK-Wisp</code></p></blockquote> <ul><li>coroutine解决的是&quot;协作式多任务&quot;</li> <li>visitor（访问者）模式解决的是&quot;对修改关闭，对扩展开放&quot;, &quot;它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作&quot;</li></ul> <ul><li><a href="https://github.com/topics/coroutines" target="_blank" rel="noopener noreferrer">https://github.com/topics/coroutines<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/topics/coroutine" target="_blank" rel="noopener noreferrer">https://github.com/topics/coroutine<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/topics/async" target="_blank" rel="noopener noreferrer">https://github.com/topics/async<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/topics/async-await" target="_blank" rel="noopener noreferrer">https://github.com/topics/async-await<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/topics/asynchronous" target="_blank" rel="noopener noreferrer">https://github.com/topics/asynchronous<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://www.cnblogs.com/tohxyblog/p/10712798.html" target="_blank" rel="noopener noreferrer">异步时代-java的协程路在何方<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/qiansg123/article/details/80123051" target="_blank" rel="noopener noreferrer">次时代Java编程（一）：Java里的协程<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="http://kailing.pub/article/index/arcid/252.html" target="_blank" rel="noopener noreferrer">java协程框架quasar和kotlin中的协程<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/kilim/kilim" target="_blank" rel="noopener noreferrer">https://github.com/kilim/kilim<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="http://chen-tao.github.io/2015/10/02/kilim-work-way/" target="_blank" rel="noopener noreferrer">Kilim工作原理<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li> <li><a href="https://github.com/puniverse/quasar" target="_blank" rel="noopener noreferrer">https://github.com/puniverse/quasar<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://blog.csdn.net/guzhangyu12345/article/details/84666423" target="_blank" rel="noopener noreferrer">quasar从原理到代码应用<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li> <li><a href="https://github.com/esoco/coroutines" target="_blank" rel="noopener noreferrer">https://github.com/esoco/coroutines<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/offbynull/coroutines" target="_blank" rel="noopener noreferrer">https://github.com/offbynull/coroutines<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/electronicarts/ea-async" target="_blank" rel="noopener noreferrer">https://github.com/electronicarts/ea-async<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="http"><a href="#http" class="header-anchor">#</a> HTTP</h2> <p><strong>常量</strong></p> <ul><li><code>java.net.HttpURLConnection</code></li> <li><code>io.netty.handler.codec.http.HttpResponseStatus</code></li> <li><code>org.springframework.http.HttpStatus</code></li> <li><code>org.apache.http.HttpStatus</code></li> <li><code>org.asynchttpclient.util.HttpConstants</code></li> <li><code>org.apache.http.protocol.HTTP</code></li> <li><code>org.springframework.http.HttpHeaders</code></li> <li><code>javax.ws.rs.HttpMethod</code></li> <li><code>org.springframework.http.HttpMethod</code></li></ul> <p><strong>Mime/Content-Type/Media-Type</strong></p> <ul><li><a href="https://github.com/topics/mime" target="_blank" rel="noopener noreferrer">https://github.com/topics/mime<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><code>com.google.common.net.MediaType</code> guava</li> <li><code>javax.ws.rs.core.MediaType</code> Jersey框架</li> <li><code>org.springframework.http.MediaType</code>和<code>org.springframework.util.MimeTypeUtils</code> spring框架</li> <li>在Tomcat配置文件<code>conf/web.xml</code>中的<code>Default MIME Type Mappings</code>部分定义</li> <li>nginx配置文件<code>conf/mime.types</code>中定义</li></ul> <p><strong>HTTP实现依赖库</strong></p> <ul><li><code>HttpURLConnection</code> Java自带API</li> <li><code>HttpClient</code> JDK11的API <a href="https://segmentfault.com/a/1190000016555671" target="_blank" rel="noopener noreferrer">Java11 HttpClient小试牛刀<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><code>RestTemplate</code> 默认实现是<code>HttpURLConnection</code>，默认使用HttpMessageConverter将Http消息转换成POJO 或POJO转化成Http消息
<ul><li><code>ForEntity</code>返回<code>ResponseEntity</code>响应码、响应消息体等</li> <li><code>ForObject</code>只返回消息体</li> <li><code>exchange</code> 配合<code>HttpEntity</code>或<code>RequestEntity</code>使用，返回<code>ResponseEntity</code></li></ul></li> <li><code>WebClient</code> 是<code>Spring 5.0</code>开始提供的非阻塞响应式编程的Http工具。</li> <li><code>Apache HttpComponents</code> <a href="http://hc.apache.org" target="_blank" rel="noopener noreferrer">http://hc.apache.org<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><code>okHttp</code> <a href="https://github.com/square/okhttp" target="_blank" rel="noopener noreferrer">https://github.com/square/okhttp<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><code>Netty</code></li> <li><code>google-http-java-client</code> <a href="https://github.com/googleapis/google-http-java-client" target="_blank" rel="noopener noreferrer">https://github.com/googleapis/google-http-java-client<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><code>WebSocket</code> <a href="https://github.com/eclipse-ee4j/websocket-api" target="_blank" rel="noopener noreferrer">https://github.com/eclipse-ee4j/websocket-api<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/OpenFeign" target="_blank" rel="noopener noreferrer">https://github.com/OpenFeign<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/square/retrofit" target="_blank" rel="noopener noreferrer">https://github.com/square/retrofit<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <ul><li><a href="https://github.com/LianjiaTech/retrofit-spring-boot-starter" target="_blank" rel="noopener noreferrer">https://github.com/LianjiaTech/retrofit-spring-boot-starter<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li> <li>使用Java 8,Netty和Reactive原则 <a href="https://github.com/ratpack/ratpack" target="_blank" rel="noopener noreferrer">https://github.com/ratpack/ratpack<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://juejin.im/post/5e156c80f265da5d3c6de72a" target="_blank" rel="noopener noreferrer">HTTP客户端连接，选择HttpClient还是OkHttp？<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><strong>Apache HttpClient GET拼接URL参数</strong></p> <div class="language-java extra-class"><pre class="language-java"><code><span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HashMap</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
params<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;key1&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;value1&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
params<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">&quot;key2&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;value2&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">NameValuePair</span><span class="token punctuation">&gt;</span></span> nvps <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">NameValuePair</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 通过map集成entrySet方法获取entity循环遍历，获取迭代器</span>
<span class="token class-name">Iterator</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Entry</span><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span><span class="token punctuation">&gt;</span></span> iterator <span class="token operator">=</span> params<span class="token punctuation">.</span><span class="token function">entrySet</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">iterator</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">while</span> <span class="token punctuation">(</span>iterator<span class="token punctuation">.</span><span class="token function">hasNext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token class-name">Entry</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">Object</span><span class="token punctuation">&gt;</span></span> mapEntry <span class="token operator">=</span> iterator<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    nvps<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">BasicNameValuePair</span><span class="token punctuation">(</span>mapEntry<span class="token punctuation">.</span><span class="token function">getKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> mapEntry<span class="token punctuation">.</span><span class="token function">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">// 由于GET请求的参数都是拼装在URL地址后方，所以我们要构建一个URL，带参数</span>

<span class="token comment">// 方式一：使用setParameters</span>
<span class="token class-name">URIBuilder</span> uriBuilder <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">URIBuilder</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 封装请求参数</span>
uriBuilder<span class="token punctuation">.</span><span class="token function">setParameters</span><span class="token punctuation">(</span>nvps<span class="token punctuation">)</span><span class="token punctuation">;</span>
uriBuilder<span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 方式二：使用setParameter</span>
<span class="token class-name">URIBuilder</span> uriBuilder <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">URIBuilder</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 封装请求参数</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token class-name">String</span> key <span class="token operator">:</span> params<span class="token punctuation">.</span><span class="token function">keySet</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    uriBuilder<span class="token punctuation">.</span><span class="token function">setParameter</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> params<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
uriBuilder<span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 方式三：转换参数并拼接</span>
url <span class="token operator">+=</span> <span class="token string">&quot;?&quot;</span> <span class="token operator">+</span> <span class="token class-name">EntityUtils</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">UrlEncodedFormEntity</span><span class="token punctuation">(</span>nvps<span class="token punctuation">,</span> <span class="token class-name">Consts</span><span class="token punctuation">.</span>UTF_8<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token class-name">URIBuilder</span> uriBuilder <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">URIBuilder</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">;</span>
uriBuilder<span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>根据HttpGet反向获取键值对列表</li></ul> <div class="language-java extra-class"><pre class="language-java"><code><span class="token class-name">HttpGet</span> request <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">HttpGet</span><span class="token punctuation">(</span><span class="token string">&quot;http://example.com/?var=1&amp;var=2&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//获取键值对列表</span>
<span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">NameValuePair</span><span class="token punctuation">&gt;</span></span> params <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">URIBuilder</span><span class="token punctuation">(</span>request<span class="token punctuation">.</span><span class="token function">getURI</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getQueryParams</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//转换为键值对字符串</span>
<span class="token class-name">String</span> str <span class="token operator">=</span> <span class="token class-name">EntityUtils</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">UrlEncodedFormEntity</span><span class="token punctuation">(</span>params<span class="token punctuation">,</span> <span class="token class-name">Consts</span><span class="token punctuation">.</span>UTF_8<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="泛型generics"><a href="#泛型generics" class="header-anchor">#</a> 泛型generics</h2> <ul><li><a href="https://www.jianshu.com/p/90948ff4a940" target="_blank" rel="noopener noreferrer">Java泛型的协变、逆变和不变<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/zy_jibai/article/details/90082239" target="_blank" rel="noopener noreferrer">图解java泛型的协变和逆变<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li>协变(<code>&lt;? extends T&gt;</code>)</li> <li>逆变(<code>&lt;? super T&gt;</code>)</li> <li>不变(<code>T</code>)</li></ul> <p><strong>泛型三种常用的使用方式：</strong></p> <ul><li><a href="https://www.cnblogs.com/coprince/p/8603492.html" target="_blank" rel="noopener noreferrer">java 泛型详解-绝对是对泛型方法讲解最详细的，没有之一<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <blockquote><p>可以有多个类型变量</p></blockquote> <ul><li>泛型类：在类名后指定类型变量，如：<code>public class Pair&lt;T, U&gt; {</code></li> <li>泛型接口：在接口名后指定类型变量，如：<code>public interface Generator&lt;T, U&gt; {</code></li> <li>泛型方法：在修饰符后，返回类型前指定类型变量，如：<code>public static &lt;T extends Object, E&gt; T test(Class&lt;T&gt; a, Class&lt;E&gt; b) {</code></li></ul></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/woytu/notes-vuepress/edit/master//Java/Java笔记.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2021-06-16 15:40:13</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/Java/Java构建管理.html" class="prev">
        Java构建管理
      </a></span> <span class="next"><a href="/Java/ORM.html">
        ORM
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.269009d6.js" defer></script><script src="/assets/js/3.974b9720.js" defer></script><script src="/assets/js/28.c124245a.js" defer></script>
  </body>
</html>
